;; host/sort.scm - (c) rohan drape, 2001-2005

(module sort mzscheme

;; There is a single general-purpose sort procedure for lists and
;; vectors.  SRFI-32 provides comprehensive sorting algorithms.

(require (rename (lib "list.ss") mergesort mergesort))

;; Must provide 'list-sort' as a simple unstable non-destructive sort
;; algorithm.  When applied to two arguments `comparison' should
;; evaluate to '#t' iff the first argument is less than the second.
;; Evaluates to the sorted list.

(define sort mergesort)

;; Must provide 'vector-sort' as a simple unstable non-destructive
;; sort algorithm.  When applied to two arguments `comparison' should
;; evaluate to '#t' iff the first argument is less than the second.
;; Evaluates to the sorted vector.

(define (vector-sort v comparison)
  (list->vector (mergesort (vector->list v) comparison)))

(provide (all-defined)))
